<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="5" :sm="8">
            <a-form-item label="所属区域">
              <j-select-depart placeholder="请选择" v-model="queryParam.areaId" />
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="8">
            <a-form-item label="管点类型">
              <j-dict-select-tag
                placeholder="请选择管点类型"
                v-model="queryParam.pipType"
                dictCode="ps_pip_point_type"
              />
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="8">
            <a-form-item label="安装点名称">
              <a-input placeholder="模糊查询" v-model="name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="8">
            <a-form-item label="道路">
              <a-input placeholder="请输入" v-model="street"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="8">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="customerSearchReset" icon="reload" style="margin-left: 8px"
                >重置</a-button
              >
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('安装点位表')">导出</a-button>
      <a-upload
        name="file"
        :showUploadList="false"
        :multiple="false"
        :headers="tokenHeader"
        :action="importExcelUrl"
        @change="handleImportExcel"
      >
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <!-- <j-super-query
        :fieldList="superFieldList"
        ref="superQueryModal"
        @handleSuperQuery="handleSuperQuery"
      ></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown> -->
    </div>

    <!-- table区域-begin -->
    <div>
      <!-- <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div> -->

      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <!-- :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" -->
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text, record">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            :preview="record.id"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a @click="handleChangePipPoint(record)">成为管点</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>

    <install-point-modal ref="modalForm" @ok="modalFormOk"></install-point-modal>
    <ChangePipPointModal ref="modalForm2" @ok="modalFormOk"></ChangePipPointModal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import InstallPointModal from './modules/InstallPoint/InstallPointModal'
import ChangePipPointModal from './modules/InstallPoint/ChangePipModal'

import { filterDictTextByCache } from '@/components/dict/JDictSelectUtil'

export default {
  name: 'InstallPointList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    InstallPointModal,
    ChangePipPointModal,
  },
  data() {
    return {
      description: '安装点位表管理页面',
      name: '',
      street: '',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: (t, r, index) => {
            const { pageSize, current } = this.ipagination
            return (current - 1) * pageSize + parseInt(index) + 1
          },
        },
        {
          title: '安装点名称',
          align: 'center',
          dataIndex: 'name',
        },
        {
          title: '点类型',
          align: 'center',
          dataIndex: 'type',
          customRender: (text, record, index) => {
            return filterDictTextByCache('ps_pip_point_type', text) || '--'
          },
        },
        {
          title: '进/出口',
          align: 'center',
          dataIndex: 'openingType',
          customRender: (text, record, index) => {
            return text == 1 ? '进水口' : text == 2 ? '出水口' : '--'
          },
        },
        {
          title: '关联点位编号',
          align: 'center',
          dataIndex: 'associationPosPointNo',
        },
        {
          title: '点编号',
          align: 'center',
          dataIndex: 'no',
        },
        {
          title: '经度',
          align: 'center',
          dataIndex: 'longitude',
        },
        {
          title: '纬度',
          align: 'center',
          dataIndex: 'latitude',
        },
        {
          title: '道路',
          align: 'center',
          dataIndex: 'street',
        },
        {
          title: '区域',
          align: 'center',
          dataIndex: 'areaId_dictText',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/terminal/installPoint/list',
        delete: '/terminal/installPoint/delete',
        deleteBatch: '/terminal/installPoint/deleteBatch',
        exportXlsUrl: '/terminal/installPoint/exportXls',
        importExcelUrl: 'terminal/installPoint/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  watch: {
    name(name) {
      if (name) {
        this.queryParam.name = `*${name}*`
      } else {
        this.queryParam.name = ''
      }
    },
    street(street) {
      if (street) {
        this.queryParam.street = `*${street}*`
      } else {
        this.queryParam.street = ''
      }
    },
  },
  methods: {
    customerSearchReset() {
      this.name = ''
      this.street = ''
      this.searchReset()
    },
    handleChangePipPoint(record) {
      this.$refs.modalForm2.edit(record)
      this.$refs.modalForm2.title = '成为管点'
      this.$refs.modalForm2.disableSubmit = false
    },
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'name', text: '名称', dictCode: '' })
      fieldList.push({ type: 'int', value: 'type', text: '类型', dictCode: '' })
      fieldList.push({ type: 'int', value: 'openingType', text: '进出口类型', dictCode: '' })
      fieldList.push({ type: 'string', value: 'no', text: '编号', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'longitude', text: '经度', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'latitude', text: '纬度', dictCode: '' })
      fieldList.push({ type: 'string', value: 'street', text: '道路', dictCode: '' })
      this.superFieldList = fieldList
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
